<%@ page pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/jsp/base/taglibs.jsp"%>
<html>
	<head>
		<link href="${ctx}/css/main.css" rel="stylesheet" type="text/css" />
		<script type="text/javascript" src="${ctx}/js/xhEditor/jquery-1.4.2.min.js"></script>
		<script type="text/javascript" src="${ctx}/js/xhEditor/xheditor-zh-cn.min.js"></script>
		<script language="javascript">
			var message = '${message}';
			if(message != ''){
				alert(message);
			}
			
			function doDelete(action,id){
				if(confirm('是否确认删除？')){
					location.href = "${ctx}/" + action + "?id=" + id ;
				}
			}
			
			function deleteRef(action,id){
				if(confirm('是否确认删除？')){
					document.getElementById("refId").value = id;
					submitAction(action);
				}
			}
			
			function select(action,id){
				location.href = "${ctx}/" + action + "?id=" + id;
			}
			
			function clickFile(action,fileName){
				location.href = "${ctx}/" + action + "?fileName=" + fileName;
			}
			
			function submitAction(action){
				document.manageForm.action = action ;
				document.manageForm.submit();
			}
			
			function init(){
				document.getElementById("baikeWord").value = "";
				document.getElementById("baikeType").value = "";
				document.getElementById("baikeDesc").value = "";
				document.getElementById("localFile").outerHTML = document.getElementById("localFile").outerHTML;
			}
			
			function saveAction(action) {
				document.getElementById("baikeDesc").value = $('#baikeDesc').val();
				if(document.getElementById("baikeWord").value == '') {
					alert('请输入百科词条');
					return ;
				}
				if(document.getElementById("baikeType").value == '') {
					alert('请输入百科类别');
					return ;
				}
				if(document.getElementById("baikeDesc").value == '') {
					alert('请输入百科内容');
					return ;
				}
				submitAction(action);
			}
			
			function validateFileType() {
				fileName = manageForm.localFile.value;
				fileType = fileName.substr(fileName.lastIndexOf(".")).toLowerCase(); 
				if(fileType != '.jpg' && fileType != '.png' && fileType != '.jpeg' && fileType != '.gif' && fileType != '.bmp'){
					alert('图片文件类型错误');
					manageForm.localFile.outerHTML = manageForm.localFile.outerHTML;
					return false;
				}
			}
		</script>
	</head>
	
	<body>
		<form method="post" action="" name="manageForm" ENCTYPE="multipart/form-data">
			<table border="0" cellspacing="1" cellpadding="3" align="center" width="100%">
				<tr>
					<td class="td11" align="left" colspan="4">
						<input type="button" name="search" value="保存" onClick="saveAction('saveBaikeInfo.ac')">
						<c:if test="${!empty baikeInfo.id}">
							&nbsp;&nbsp;<input type="button" name="delete" value="删除" onClick="doDelete('deleteBaikeInfo.ac','${baikeInfo.id}')">
						</c:if>
						<c:if test="${empty baikeInfo.id}">
							&nbsp;&nbsp;<input type="button" name="reset" value="重置" onClick="init()">
						</c:if>
						&nbsp;&nbsp;<input type="button" name="back" value="返回" onClick="submitAction('backToBaikeInfoSearch.ac')">
					</td>
				</tr>
				<tr>
					<td width="20%" class="td2">
						百科词条  <span style="color:red;vertical-align:middle;">*</span>
					</td>
					<td width="30%" class="td2">
						<input type="hidden" name="id" value="${baikeInfo.id}">
						<input type="hidden" name="fileName" value="${baikeInfo.fileName}">
						<input type="hidden" name="refId" value="">
						<c:if test="${empty baikeInfo.id}">
							<input type="text" name="baikeWord" size="32" value="${baikeInfo.baikeWord}">
						</c:if>
						<c:if test="${!empty baikeInfo.id}">
							<input readonly="readonly" style="color:grey" type="text" name="baikeWord" value="${baikeInfo.baikeWord}">
						</c:if>
					</td>
					<td width="20%" class="td2">
						百科类别  <span style="color:red;vertical-align:middle;">*</span>
					</td>
					<td width="30%" class="td2">
						<select name="baikeType" id="baikeType" style="width:200px">
							<c:forEach var="code" items="${sessionScope.T_baikeTypeList}">
								<c:if test="${baikeInfo.baikeType == code.baikeType}">
									<option value="${code.baikeType}" selected="selected">${code.baikeTypeName}</option>
								</c:if>
								<c:if test="${baikeInfo.baikeType != code.baikeType}">
									<option value="${code.baikeType}">${code.baikeTypeName}</option>
								</c:if>
							</c:forEach>
						</select>
					</td>
				</tr>
				<tr>
					<td width="20%" class="td2">
						新闻图片
					</td>
					<td width="20%" class="td2" colspan="3">
						<input type="file" name="localFile" size="40" value="" onchange="validateFileType();">
						<span style="color:red;vertical-align:middle;">&nbsp;&nbsp;&nbsp;&nbsp;图片必须是以jpg,gif,jpeg,png,bmp为后缀文件</span>
					</td>
				</tr>
				<tr>
					<td width="10%" class="td2">  
						文件
					</td>
					<td width="30%" class="td2" colspan="3">
						<a href="javascript:clickFile('getBaikePhoto.ac','${baikeInfo.fileName}');">${baikeInfo.fileName}</a>
					</td>
				</tr>
				<tr>
					<td width="20%" class="td2" colspan="4">
						百科内容  <span style="color:red;vertical-align:middle;">*</span>
					</td>
				</tr>
				<tr>
					<td width="100%" class="td2" colspan="4" align="center">
						<textarea id="baikeDesc" name="baikeDesc" class="xheditor {tools:'Cut,Copy,Paste,Pastetext,Blocktag,Fontface,FontSize,Bold,Italic,Underline,Strikethrough,FontColor,BackColor,SelectAll,Removeformat,Align,List,Outdent,Indent,Link,Unlink,|,Preview,Print,Fullscreen',skin:'vista',width:750,height:380}">
							${baikeInfo.baikeDesc}
						</textarea>
					</td>
				</tr>
			</table>
			<BR>
			<c:if test="${!empty baikeRefInfoList}">
				<table border="0" cellspacing="1" cellpadding="3" align="center" width="100%">
					<tr>
						<td width="15%" class="td1" align="center">
							动作
						</td>
						<td width="35%" class="td1" align="center">
							创建人
						</td>
						<td width="35%" class="td1" align="center">
							创建时间
						</td>
						<td width="15%" class="td1" align="center">
							删除
						</td>
					</tr>
					<c:forEach var="baikeRefInfo" items="${baikeRefInfoList}">
						<tr>
							<td class="td2" align="center">
								<a href="javascript:select('selectBaikeRefInfo.ac','${baikeRefInfo.id}');">选择</a>
							</td>
							<td class="td2">
								${baikeRefInfo.creator}
							</td>
							<td class="td2" align="center">
								${baikeRefInfo.modifyDate}
							</td>
							<td class="td2" align="center">
								<img src="${ctx}/images/delete0.png" onclick="javascript:deleteRef('deleteBaikeRef.ac','${baikeRefInfo.id}');">
							</td>
						</tr>
					</c:forEach>
				</table>
			</c:if>
		</form>
	</body>
</html>